 
	$(document).ready(function(){
		jQuery.validator.addMethod("username", function(value, element) { 
		  return this.optional(element) || /^[a-zA-Z]{1}([a-zA-Z0-9]){4,15}$/.test(value); 
		}, "登录名只能在4-16位之间，请用英文小写");
			//验证部分
		$("#teacherinfoEdit").validate({
            rules: {
                enname : {
                    maxlength : 50,
					username:true
                },
                tel : {
                    maxlength : 20
                },
				email : {
                    maxlength : 150,
					email:true
                },
				address : {
                    maxlength : 250
                },
				post : {
                    maxlength : 50,
					number : true
                },
				qq : {
                    maxlength : 20,
					number : true
                },
				interest : {
                    maxlength : 1000
                },
				introduce : {
                    maxlength : 1000
                }
            },
            messages: {
                enname : {
                    maxlength : "英文名长度不能大于50！"
                },
                tel : {
                    maxlength : "电话填写长度不能大于20！"
                },
				email : {
                    maxlength : "电子邮箱长度不能大于150！",
					email : "请填写正确的邮箱！"
                },
				address : {
                    maxlength : "家庭住址长度不能大于250！"
                },
				post : {
                    maxlength : "姓名长度不能大于20！",
					number :  "邮政编码应该为数字！"
                },
				qq : {
                    maxlength : "姓名长度不能大于20！",
					number :  "QQ号码必须为数字！"
				},
				interest : {
                    maxlength : "兴趣爱好的长度不能大于500个汉字！"
                },
				introduce : {
                    maxlength : "个人介绍的长度不能大于500个汉字！"
                }
            }
        });
		/* Example 1 */
		var button = $('#upload_but'), interval;
		
		new AjaxUpload(button, {
			action: '/blog/fileUploader/process', 
			name: 'file',
            responseType: 'json',
            data : {
				'upload' : "studentavatar",
				'pid' : "1",
				'successAction' : "upload",
				'successController' : "teacherInfoAjax",
				'errorAction' : "upload",
				'errorController' : "teacherInfoAjax"
			}, 

			onSubmit : function(file, ext){
				// change button text, when user selects file			
				button.text('Uploading');
								
				// If you want to allow uploading only 1 file at time,
				// you can disable upload button
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = button.text();
					if (text.length < 13){
						button.text(text + '.');					
					} else {
						button.text('上传');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				button.text('点击上传');
							
				window.clearInterval(interval);
							
				// enable upload button
				this.enable();

                //alert(file);
                if (response.success)
                {	// add file to the list
				    $('.files').html('<img src="/blog/download/index/'+response.message+'"/>');
                    $('#avatarLogo').val(response.message);
                }else{
                    $(".files").html('<div class="errors">' + response.message + '</div');
                    $('#avatarLogo').val('');
                }
			}
		});

	});
 